package com.itcam.dao.impl;

import com.itcam.dao.StudentDao;
import com.itcam.pojo.Student;

import java.util.List;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

public class StudentDaoImpl implements StudentDao {
    private JdbcTemplate jdbcTemplate;

    // 注入jdbcTemplate对象
    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    @Override
    public List<Student> queryAll() {
        // jdbcTemplate进行数据库的查询，ioc容器进行装配，不要自己去实例化
        String sql = "select id,name,gender,age,class as classes from students";

        List<Student> students = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Student.class));

        System.out.println("studentDao: " + students);

        return students;
    }
}
